1 // ----------------------------------------------------------------------------
2 // <copyright file=
"Enums.cs" company="Exit Games GmbH">
3 // PhotonNetwork Framework
for Unity - Copyright (C) 2011 Exit Games GmbH
4 // </copyright>
5 // <summary>
6 //
7 // </summary>
8 // <author>developer@exitgames.com</author>
9 // ----------------------------------------------------------------------------

10
11 #pragma warning disable
1587
12 ///
\file
13 ///
<summary>Wraps up several of the commonly used enumerations. </summary>
14 #pragma warning restore
1587
15
16
17 using
ExitGames.Client.Photon;
18
19
20 ///
<summary>
21 ///
This enum defines the set of MonoMessages Photon Unity Networking is using as callbacks. Implemented by PunBehaviour.
22 ///
</summary>
23 ///
<remarks>
24 ///
Much like "Update()" in Unity, PUN will call methods in specific situations.
25 ///
Often, these methods are triggered when network operations complete (example: when joining a room).
26 ///

27 ///
All those methods are defined and described in this enum and implemented by PunBehaviour
28 ///
(which makes it easy to implement them as override).
29 ///

30 ///
Each entry is the name of such a method and the description tells you when it gets used by PUN.
31 ///

32 ///
Make sure to read the remarks per entry as some methods have optional parameters.
33 ///
</remarks>
34 ///
\ingroup publicApi
35 public
enum PhotonNetworkingMessage
36 {

37     ///
<summary>
38     ///
Called when the initial connection got established but before you can use the server. OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready.
39     ///
</summary>
40     ///
<remarks>
41     ///
This callback is only useful to detect if the server can be reached at all (technically).
42     ///
Most often, it's enough to implement OnFailedToConnectToPhoton() and OnDisconnectedFromPhoton().
43     ///

44     ///
<i>OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready.</i>
45     ///

46     ///
When this is called, the low level connection is established and PUN will send your AppId, the user, etc in the background.
47     ///
This is not called for transitions from the masterserver to game servers.
48     ///

49     ///
Example: void OnConnectedToPhoton() { ... }
50     ///
</remarks>
51     OnConnectedToPhoton,

52
53     ///
<summary>
54     ///
Called when the local user/client left a room.
55     ///
</summary>
56     ///
<remarks>
57     ///
When leaving a room, PUN brings you back to the Master Server.
58     ///
Before you can use lobbies and join or create rooms, OnJoinedLobby() or OnConnectedToMaster() will get called again.
59     ///

60     ///
Example: void OnLeftRoom() { ... }
61     ///
</remarks>
62     OnLeftRoom,

63
64     ///
<summary>
65     ///
Called after switching to a new MasterClient when the current one leaves. The former already got removed from the player list.
66     ///
</summary>
67     ///
<remarks>
68     ///
This is not called when this client enters a room.
69     ///

70     ///
Example: void OnMasterClientSwitched(PhotonPlayer newMasterClient) { ... }
71     ///
</remarks>
72     OnMasterClientSwitched,

73
74     ///
<summary>
75     ///
Called when a CreateRoom() call failed. Optional parameters provide ErrorCode and message.
76     ///
</summary>
77     ///
<remarks>
78     ///
Most likely because the room name is already in use (some other client was faster than you).
79     ///
PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.
80     ///

81     ///
Example: void OnPhotonCreateRoomFailed() { ... }
82     ///

83     ///
Example: void OnPhotonCreateRoomFailed(object[] codeAndMsg) { // codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }
84     ///
</remarks>
85     OnPhotonCreateRoomFailed,

86
87     ///
<summary>
88     ///
Called when a JoinRoom() call failed. Optional parameters provide ErrorCode and message.
89     ///
</summary>
90     ///
<remarks>
91     ///
Most likely error is that the room does not exist or the room is full (some other client was faster than you).
92     ///
PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.
93     ///

94     ///
Example: void OnPhotonJoinRoomFailed() { ... }
95     ///

96     ///
Example: void OnPhotonJoinRoomFailed(object[] codeAndMsg) { // codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }
97     ///
</remarks>
98     OnPhotonJoinRoomFailed,

99
100     ///
<summary>
101     ///
Called when this client created a room and entered it. OnJoinedRoom() will be called as well.
102     ///
</summary>
103     ///
<remarks>
104     ///
This callback is only called on the client which created a room (see PhotonNetwork.CreateRoom).
105     ///

106     ///
As any client might close (or drop connection) anytime, there is a chance that the
107     ///
creator of a room does not execute OnCreatedRoom.
108     ///

109     ///
If you need specific room properties or a "start signal", it is safer to implement
110     ///
OnMasterClientSwitched() and to make the new MasterClient check the room's state.
111     ///

112     ///
Example: void OnCreatedRoom() { ... }
113     ///
</remarks>
114     OnCreatedRoom,

115
116     ///
<summary>
117     ///
Called on entering a lobby on the Master Server. The actual room-list updates will call OnReceivedRoomListUpdate().
118     ///
</summary>
119     ///
<remarks>
120     ///
Note: When PhotonNetwork.autoJoinLobby is false, OnConnectedToMaster() will be called and the room list won't become available.
121     ///

122     ///
While in the lobby, the roomlist is automatically updated in fixed intervals (which you can't modify).
123     ///

124     ///
Example: void OnJoinedLobby() { ... }
125     ///
</remarks>
126     OnJoinedLobby,

127
128     ///
<summary>
129     ///
Called after leaving a lobby.
130     ///
</summary>
131     ///
<remarks>
132     ///
When you leave a lobby, [CreateRoom](@ref PhotonNetwork.CreateRoom) and [JoinRandomRoom](@ref PhotonNetwork.JoinRandomRoom)
133     ///
automatically refer to the default lobby.
134     ///

135     ///
Example: void OnLeftLobby() { ... }
136     ///
</remarks>
137     OnLeftLobby,

138
139     ///
<summary>
140     ///
Called after disconnecting from the Photon server.
141     ///
</summary>
142     ///
<remarks>
143     ///
In some cases, other callbacks are called before OnDisconnectedFromPhoton is called.
144     ///
Examples: OnConnectionFail() and OnFailedToConnectToPhoton().
145     ///

146     ///
Example: void OnDisconnectedFromPhoton() { ... }
147     ///
</remarks>
148     OnDisconnectedFromPhoton,

149
150     ///
<summary>
151     ///
Called when something causes the connection to fail (after it was established), followed by a call to OnDisconnectedFromPhoton().
152     ///
</summary>
153     ///
<remarks>
154     ///
If the server could not be reached in the first place, OnFailedToConnectToPhoton is called instead.
155     ///
The reason for the error is provided as StatusCode.
156     ///

157     ///
Example: void OnConnectionFail(DisconnectCause cause) { ... }
158     ///
</remarks>
159     OnConnectionFail,

160
161     ///
<summary>
162     ///
Called if a connect call to the Photon server failed before the connection was established, followed by a call to OnDisconnectedFromPhoton().
163     ///
</summary>
164     ///
<remarks>
165     ///
OnConnectionFail only gets called when a connection to a Photon server was established in the first place.
166     ///

167     ///
Example: void OnFailedToConnectToPhoton(DisconnectCause cause) { ... }
168     ///
</remarks>
169     OnFailedToConnectToPhoton,

170
171     ///
<summary>
172     ///
Called for any update of the room listing (no matter if "new" list or "update for known" list). Only called in the Lobby state (on master server).
173     ///
</summary>
174     ///
<remarks>
175     ///
Not all types of lobbies provive a listing of rooms to the client. Some are silent and specialized for server-side matchmaking.
176     ///

177     ///
PUN provides the list of rooms by PhotonNetwork.GetRoomList().
178     ///
Each item is a RoomInfo which might include custom properties
179     ///
(provided you defined those as lobby-listed when creating a room).
180     ///

181     ///
Example: void OnReceivedRoomListUpdate() { ... }
182     ///
</remarks>
183     OnReceivedRoomListUpdate,

184
185     ///
<summary>
186     ///
Called when entering a room (by creating or joining it). Called on all clients (including the Master Client).
187     ///
</summary>
188     ///
<remarks>
189     ///
This method is commonly used to instantiate player characters.
190     ///
If a match has to be started "actively", you can instead call an [RPC](@ref PhotonView.RPC) triggered by a user's button-press or a timer.
191     ///

192     ///
When this is called, you can usually already access the existing players in the room via PhotonNetwork.playerList.
193     ///
Also, all custom properties should be already available as Room.customProperties. Check Room.playerCount to find out if
194     ///
enough players are in the room to start playing.
195     ///

196     ///
Example: void OnJoinedRoom() { ... }
197     ///
</remarks>
198     OnJoinedRoom,

199
200     ///
<summary>
201     ///
Called when a remote player entered the room. This PhotonPlayer is already added to the playerlist at this time.
202     ///
</summary>
203     ///
<remarks>
204     ///
If your game starts with a certain number of players, this callback can be useful to check the
205     ///
Room.playerCount and find out if you can start.
206     ///

207     ///
Example: void OnPhotonPlayerConnected(PhotonPlayer newPlayer) { ... }
208     ///
</remarks>
209     OnPhotonPlayerConnected,

210
211     ///
<summary>
212     ///
Called when a remote player left the room. This PhotonPlayer is already removed from the playerlist at this time.
213     ///
</summary>
214     ///
<remarks>
215     ///
When your client calls PhotonNetwork.leaveRoom, PUN will call this method on the remaining clients.
216     ///
When a remote client drops connection or gets closed, this callback gets executed. after a timeout
217     ///
of several seconds.
218     ///

219     ///
Example: void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { ... }
220     ///
</remarks>
221     OnPhotonPlayerDisconnected,

222
223     ///
<summary>
224     ///
Called after a JoinRandom() call failed. Optional parameters provide ErrorCode and message.
225     ///
</summary>
226     ///
<remarks>
227     ///
Most likely all rooms are full or no rooms are available.
228     ///
When using multiple lobbies (via JoinLobby or TypedLobby), another lobby might have more/fitting rooms.
229     ///
PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.
230     ///

231     ///
Example: void OnPhotonRandomJoinFailed() { ... }
232     ///

233     ///
Example: void OnPhotonRandomJoinFailed(object[] codeAndMsg) { // codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }
234     ///
</remarks>
235     OnPhotonRandomJoinFailed,

236
237     ///
<summary>
238     ///
Called after the connection to the master is established and authenticated but only when PhotonNetwork.autoJoinLobby is false.
239     ///
</summary>
240     ///
<remarks>
241     ///
If you set PhotonNetwork.autoJoinLobby to true, OnJoinedLobby() will be called instead of this.
242     ///

243     ///
You can join rooms and create them even without being in a lobby. The default lobby is used in that case.
244     ///
The list of available rooms won't become available unless you join a lobby via PhotonNetwork.joinLobby.
245     ///

246     ///
Example: void OnConnectedToMaster() { ... }
247     ///
</remarks>
248     OnConnectedToMaster,

249
250     ///
<summary>
251     ///
Implement to customize the data a PhotonView regularly synchronizes. Called every 'network-update' when observed by PhotonView.
252     ///
</summary>
253     ///
<remarks>
254     ///
This method will be called in scripts that are assigned as Observed component of a PhotonView.
255     ///
PhotonNetwork.sendRateOnSerialize affects how often this method is called.
256     ///
PhotonNetwork.sendRate affects how often packages are sent by this client.
257     ///

258     ///
Implementing this method, you can customize which data a PhotonView regularly synchronizes.
259     ///
Your code defines what is being sent (content) and how your data is used by receiving clients.
260     ///

261     ///
Unlike other callbacks, <i>OnPhotonSerializeView only gets called when it is assigned
262     ///
to a PhotonView</i> as PhotonView.observed script.
263     ///

264     ///
To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the
265     ///
client that controls a PhotonView (PhotonStream.isWriting == true) and in "reading mode" on the
266     ///
remote clients that just receive that the controlling client sends.
267     ///

268     ///
If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can
269     ///
conserve bandwidth and messages (which have a limit per room/second).
270     ///

271     ///
Note that OnPhotonSerializeView is not called on remote clients when the sender does not send
272     ///
any update. This can't be used as "x-times per second Update()".
273     ///

274     ///
Example: void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { ... }
275     ///
</remarks>
276     OnPhotonSerializeView,

277
278     ///
<summary>
279     ///
Called on all scripts on a GameObject (and children) that have been Instantiated using PhotonNetwork.Instantiate.
280     ///
</summary>
281     ///
<remarks>
282     ///
PhotonMessageInfo parameter provides info about who created the object and when (based off PhotonNetworking.time).
283     ///

284     ///
Example: void OnPhotonInstantiate(PhotonMessageInfo info) { ... }
285     ///
</remarks>
286     OnPhotonInstantiate,

287
288     ///
<summary>
289     ///
Because the concurrent user limit was (temporarily) reached, this client is rejected by the server and disconnecting.
290     ///
</summary>
291     ///
<remarks>
292     ///
When this happens, the user might try again later. You can't create or join rooms in OnPhotonMaxCcuReached(), cause the client will be disconnecting.
293     ///
You can raise the CCU limits with a new license (when you host yourself) or extended subscription (when using the Photon Cloud).
294     ///
The Photon Cloud will mail you when the CCU limit was reached. This is also visible in the Dashboard (webpage).
295     ///

296     ///
Example: void OnPhotonMaxCccuReached() { ... }
297     ///
</remarks>
298     OnPhotonMaxCccuReached,

299
300     ///
<summary>
301     ///
Called when a room's custom properties changed. The propertiesThatChanged contains all that was set via Room.SetCustomProperties.
302     ///
</summary>
303     ///
<remarks>
304     ///
Since v1.25 this method has one parameter: Hashtable propertiesThatChanged.
305     ///
Changing properties must be done by Room.SetCustomProperties, which causes this callback locally, too.
306     ///

307     ///
Example: void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) { ... }
308     ///
</remarks>
309     OnPhotonCustomRoomPropertiesChanged,

310
311     ///
<summary>
312     ///
Called when custom player-properties are changed. Player and the changed properties are passed as object[].
313     ///
</summary>
314     ///
<remarks>
315     ///
Since v1.25 this method has one parameter: object[] playerAndUpdatedProps, which contains two entries.<br/>
316     ///
[0] is the affected PhotonPlayer.<br/>
317     ///
[1] is the Hashtable of properties that changed.<br/>
318     ///

319     ///
We are using a object[] due to limitations of Unity's GameObject.SendMessage (which has only one optional parameter).
320     ///
321     ///
Changing properties must be done by PhotonPlayer.SetCustomProperties, which causes this callback locally, too.
322     ///

323     ///
Example:<pre>
324     ///
void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) {
325     ///
PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;
326     ///
Hashtable props = playerAndUpdatedProps[1] as Hashtable;
327     ///
//...
328     ///
}</pre>
329     ///
</remarks>
330     OnPhotonPlayerPropertiesChanged,

331
332     ///
<summary>
333     ///
Called when the server sent the response to a FindFriends request and updated PhotonNetwork.Friends.
334     ///
</summary>
335     ///
<remarks>
336     ///
The friends list is available as PhotonNetwork.Friends, listing name, online state and
337     ///
the room a user is in (if any).
338     ///

339     ///
Example: void OnUpdatedFriendList() { ... }
340     ///
</remarks>
341     OnUpdatedFriendList,

342
343     ///
<summary>
344     ///
Called when the custom authentication failed. Followed by disconnect!
345     ///
</summary>
346     ///
<remarks>
347     ///
Custom Authentication can fail due to user-input, bad tokens/secrets.
348     ///
If authentication is successful, this method is not called. Implement OnJoinedLobby() or OnConnectedToMaster() (as usual).
349     ///

350     ///
During development of a game, it might also fail due to wrong configuration on the server side.
351     ///
In those cases, logging the debugMessage is very important.
352     ///

353     ///
Unless you setup a custom authentication service for your app (in the [Dashboard](https://cloud.exitgames.com/dashboard)),
354     ///
this won't be called!
355     ///

356     ///
Example: void OnCustomAuthenticationFailed(string debugMessage) { ... }
357     ///
</remarks>
358     OnCustomAuthenticationFailed,

359
360     ///
<summary>
361     ///
Called by PUN when the response to a WebRPC is available. See PhotonNetwork.WebRPC.
362     ///
</summary>
363     ///
<remarks>
364     ///
Important: The response.ReturnCode is 0 if Photon was able to reach your web-service.
365     ///
The content of the response is what your web-service sent. You can create a WebResponse instance from it.
366     ///
Example: WebRpcResponse webResponse = new WebRpcResponse(operationResponse);
367     ///
368     ///
Please note: Class OperationResponse is in a namespace which needs to be "used":
369     ///
using ExitGames.Client.Photon; // includes OperationResponse (and other classes)
370     ///
371     ///
The OperationResponse.ReturnCode by Photon is:
372     ///
0 for "OK"
373     ///
-3 for "Web-Service not configured" (see Dashboard / WebHooks)
374     ///
-5 for "Web-Service does now have RPC path/name" (at least for Azure)
375     ///

376     ///
Example: void OnWebRpcResponse(OperationResponse response) { ... }
377     ///
</remarks>
378     OnWebRpcResponse,

379
380     ///
<summary>
381     ///
Called when another player requests ownership of a PhotonView from you (the current owner).
382     ///
</summary>
383     ///
<remarks>
384     ///
The parameter viewAndPlayer contains:
385     ///

386     ///
PhotonView view = viewAndPlayer[0] as PhotonView;
387     ///

388     ///
PhotonPlayer requestingPlayer = viewAndPlayer[1] as PhotonPlayer;
389     ///
</remarks>
390     ///
<example>void OnOwnershipRequest(object[] viewAndPlayer) {} //</example>
391     OnOwnershipRequest,
392 }

393
394
395 ///
<summary>Used to define the level of logging output created by the PUN classes. Either log errors, info (some more) or full.</summary>
396 ///
\ingroup publicApi
397 public
enum PhotonLogLevel
398 {

399     ///
<summary>Show only errors. Minimal output. Note: Some might be "runtime errors" which you have to expect.</summary>
400     ErrorsOnly,

401     ///
<summary>Logs some of the workflow, calls and results.</summary>
402     Informational,

403     ///
<summary>Every available log call gets into the console/log. Only use for debugging.</summary>
404     Full
405 }

406
407 ///
<summary>Enum of "target" options for RPCs. These define which remote clients get your RPC call. </summary>
408 ///
\ingroup publicApi
409 public
enum PhotonTargets
410 {

411     ///
<summary>Sends the RPC to everyone else and executes it immediately on this client. Player who join later will not execute this RPC.</summary>
412     All,

413     ///
<summary>Sends the RPC to everyone else. This client does not execute the RPC. Player who join later will not execute this RPC.</summary>
414     Others,

415     ///
<summary>Sends the RPC to MasterClient only. Careful: The MasterClient might disconnect before it executes the RPC and that might cause dropped RPCs.</summary>
416     MasterClient,

417     ///
<summary>Sends the RPC to everyone else and executes it immediately on this client. New players get the RPC when they join as it's buffered (until this client leaves).</summary>
418     AllBuffered,

419     ///
<summary>Sends the RPC to everyone. This client does not execute the RPC. New players get the RPC when they join as it's buffered (until this client leaves).</summary>
420     OthersBuffered,

421     ///
<summary>Sends the RPC to everyone (including this client) through the server.</summary>
422     ///
<remarks>
423     ///
This client executes the RPC like any other when it received it from the server.
424     ///
Benefit: The server's order of sending the RPCs is the same on all clients.
425     ///
</remarks>
426     AllViaServer,

427     ///
<summary>Sends the RPC to everyone (including this client) through the server and buffers it for players joining later.</summary>
428     ///
<remarks>
429     ///
This client executes the RPC like any other when it received it from the server.
430     ///
Benefit: The server's order of sending the RPCs is the same on all clients.
431     ///
</remarks>
432     AllBufferedViaServer
433 }

434
435 ///
<summary>
436 ///
Options of lobby types available. Lobby types might be implemented in certain Photon versions and won't be available on older servers.
437 ///
</summary>
438 public
enum LobbyType :byte
439 {

440     ///
<summary>This lobby is used unless another is defined by game or JoinRandom. Room-lists will be sent and JoinRandomRoom can filter by matching properties.</summary>
441     Default =
0,
442     ///
<summary>This lobby type lists rooms like Default but JoinRandom has a parameter for SQL-like "where" clauses for filtering. This allows bigger, less, or and and combinations.</summary>
443     SqlLobby =
2
444 }

445
446 ///
<summary>Currently available cloud regions as enum.</summary>
447 ///
<remarks>
448 ///
Must match order in CloudServerRegionNames and CloudServerRegionPrefixes.
449 ///
To keep things compatible with older ServerSettings, "none" is the final value, not the first.
450 ///
</remarks>
451 public
enum CloudRegionCode { eu = 0, us = 1, asia = 2, jp = 3, au = 5, none = 4 };
452
453 ///
<summary>Available server (types) for internally used field: server.</summary>
454 public
enum ServerConnection
455 {
456     MasterServer,
457     GameServer,
458     NameServer
459 }

460
461 ///
<summary>
462 ///
High level connection state of the client. Better use the more detailed <see cref="PeerState"/>.
463 ///
</summary>
464 public
enum ConnectionState
465 {
466     Disconnected,
467     Connecting,
468     Connected,
469     Disconnecting,
470     InitializingApplication
471 }

472
473 ///
<summary>
474 ///
Detailed connection / networking peer state.
475 ///
PUN implements a loadbalancing and authentication workflow "behind the scenes", so
476 ///
some states will automatically advance to some follow up state. Those states are
477 ///
commented with "(will-change)".
478 ///
</summary>
479 ///
\ingroup publicApi
480 public
enum PeerState
481 {

482     ///
<summary>Not running. Only set before initialization and first use.</summary>
483     Uninitialized,

484
485     ///
<summary>Created and available to connect.</summary>
486     PeerCreated,

487
488     ///
<summary>Not used at the moment.</summary>
489     Queued,

490
491     ///
<summary>The application is authenticated. PUN usually joins the lobby now.</summary>
492     ///
<remarks>(will-change) Unless AutoJoinLobby is false.</remarks>
493     Authenticated,

494
495     ///
<summary>Client is in the lobby of the Master Server and gets room listings.</summary>
496     ///
<remarks>Use Join, Create or JoinRandom to get into a room to play.</remarks>
497     JoinedLobby,

498
499     ///
<summary>Disconnecting.</summary>
500     ///
<remarks>(will-change)</remarks>
501     DisconnectingFromMasterserver,

502
503     ///
<summary>Connecting to game server (to join/create a room and play).</summary>
504     ///
<remarks>(will-change)</remarks>
505     ConnectingToGameserver,

506
507     ///
<summary>Similar to Connected state but on game server. Still in process to join/create room.</summary>
508     ///
<remarks>(will-change)</remarks>
509     ConnectedToGameserver,

510
511     ///
<summary>In process to join/create room (on game server).</summary>
512     ///
<remarks>(will-change)</remarks>
513     Joining,

514
515     ///
<summary>Final state of a room join/create sequence. This client can now exchange events / call RPCs with other clients.</summary>
516     Joined,

517
518     ///
<summary>Leaving a room.</summary>
519     ///
<remarks>(will-change)</remarks>
520     Leaving,

521
522     ///
<summary>Workflow is leaving the game server and will re-connect to the master server.</summary>
523     ///
<remarks>(will-change)</remarks>
524     DisconnectingFromGameserver,

525
526     ///
<summary>Workflow is connected to master server and will establish encryption and authenticate your app.</summary>
527     ///
<remarks>(will-change)</remarks>
528     ConnectingToMasterserver,

529
530     ///
<summary>Same Queued but coming from game server.</summary>
531     ///
<remarks>(will-change)</remarks>
532     QueuedComingFromGameserver,

533
534     ///
<summary>PUN is disconnecting. This leads to Disconnected.</summary>
535     ///
<remarks>(will-change)</remarks>
536     Disconnecting,

537
538     ///
<summary>No connection is setup, ready to connect. Similar to PeerCreated.</summary>
539     Disconnected,

540
541     ///
<summary>Final state for connecting to master without joining the lobby (AutoJoinLobby is false).</summary>
542     ConnectedToMaster,

543
544     ///
<summary>Client connects to the NameServer. This process includes low level connecting and setting up encryption. When done, state becomes ConnectedToNameServer.</summary>
545     ConnectingToNameServer,

546
547     ///
<summary>Client is connected to the NameServer and established enctryption already. You should call OpGetRegions or ConnectToRegionMaster.</summary>
548     ConnectedToNameServer,

549
550     ///
<summary>When disconnecting from a Photon NameServer.</summary>
551     ///
<remarks>(will-change)</remarks>
552     DisconnectingFromNameServer,

553
554     ///
<summary>When connecting to a Photon Server, this state is intermediate before you can call any operations.</summary>
555     ///
<remarks>(will-change)</remarks>
556     Authenticating
557 }

558
559
560 // Photon properties, internally
set by PhotonNetwork (PhotonNetwork builtin properties)
561
562
563 ///
<summary>
564 ///
Summarizes the cause for a disconnect. Used in: OnConnectionFail and OnFailedToConnectToPhoton.
565 ///
</summary>
566 ///
<remarks>Extracted from the status codes from ExitGames.Client.Photon.StatusCode.</remarks>
567 ///
<seealso cref="PhotonNetworkingMessage"/>
568 ///
\ingroup publicApi
569 public
enum DisconnectCause
570 {

571     ///
<summary>Connection could not be established.
572     ///
Possible cause: Local server not running.</summary>
573     ExceptionOnConnect = StatusCode.ExceptionOnConnect,

574
575     ///
<summary>The security settings for client or server don't allow a connection (see remarks).</summary>
576     ///
<remarks>
577     ///
A common cause for this is that browser clients read a "crossdomain" file from the server.
578     ///
If that file is unavailable or not configured to let the client connect, this exception is thrown.
579     ///
Photon usually provides this crossdomain file for Unity.
580     ///
If it fails, read:
581     ///
http://doc.exitgames.com/photon-server/PolicyApp
582     ///
</remarks>
583     SecurityExceptionOnConnect = StatusCode.SecurityExceptionOnConnect,

584
585     ///
<summary>Connection timed out.
586     ///
Possible cause: Remote server not running or required ports blocked (due to router or firewall).</summary>
587     
[System.Obsolete("Replaced by clearer: DisconnectByClientTimeout")]
588     TimeoutDisconnect = StatusCode.TimeoutDisconnect,

589
590     ///
<summary>Timeout disconnect by client (which decided an ACK was missing for too long).</summary>
591     DisconnectByClientTimeout = StatusCode.TimeoutDisconnect,

592
593     ///
<summary>Exception in the receive-loop.
594     ///
Possible cause: Socket failure.</summary>
595     InternalReceiveException = StatusCode.ExceptionOnReceive,

596
597     ///
<summary>Server actively disconnected this client.</summary>
598     
[System.Obsolete("Replaced by clearer: DisconnectByServerTimeout")]
599     DisconnectByServer = StatusCode.DisconnectByServer,

600
601     ///
<summary>Timeout disconnect by server (which decided an ACK was missing for too long).</summary>
602     DisconnectByServerTimeout = StatusCode.DisconnectByServer,

603
604     ///
<summary>Server actively disconnected this client.
605     ///
Possible cause: Server's send buffer full (too much data for client).</summary>
606     DisconnectByServerLogic = StatusCode.DisconnectByServerLogic,

607
608     ///
<summary>Server actively disconnected this client.
609     ///
Possible cause: The server's user limit was hit and client was forced to disconnect (on connect).</summary>
610     DisconnectByServerUserLimit = StatusCode.DisconnectByServerUserLimit,

611
612     ///
<summary>Some exception caused the connection to close.</summary>
613     Exception = StatusCode.Exception,

614
615     ///
<summary>(32756) Authorization on the Photon Cloud failed because the app's subscription does not allow to use a particular region's server.</summary>
616     InvalidRegion = ErrorCode.InvalidRegion,

617
618     ///
<summary>(32757) Authorization on the Photon Cloud failed because the concurrent users (CCU) limit of the app's subscription is reached.</summary>
619     MaxCcuReached = ErrorCode.MaxCcuReached,

620
621     ///
<summary>(32767) The Photon Cloud rejected the sent AppId. Check your Dashboard and make sure the AppId you use is complete and correct.</summary>
622     InvalidAuthentication = ErrorCode.InvalidAuthentication,

623
624     ///
<summary>(32753) The Authentication ticket expired. Handle this by connecting again (which includes an authenticate to get a fresh ticket).</summary>
625     AuthenticationTicketExpired = ErrorCode.AuthenticationTicketExpired,
626 }

627
628 ///
<summary>
629 ///
Internal state how this peer gets into a particular room (joining it or creating it).
630 ///
</summary>
631 internal
enum JoinType
632 {
633     CreateGame,
634     JoinGame,
635     JoinRandomGame,
636     JoinOrCreateOnDemand
637 }


----------------------------------------------------------------------------

PhotonNetwork Framework for Unity - Copyright (C) 2011 Exit Games GmbH

developer@exitgames.com

----------------------------------------------------------------------------

\file

Wraps up several of the commonly used enumerations.

This enum defines the set of MonoMessages Photon Unity Networking is using as callbacks. Implemented by PunBehaviour.

Much like "Update()" in Unity, PUN will call methods in specific situations.

Often, these methods are triggered when network operations complete (example: when joining a room).

All those methods are defined and described in this enum and implemented by PunBehaviour

(which makes it easy to implement them as override).

Each entry is the name of such a method and the description tells you when it gets used by PUN.

Make sure to read the remarks per entry as some methods have optional parameters.

\ingroup publicApi

Called when the initial connection got established but before you can use the server. OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready.

This callback is only useful to detect if the server can be reached at all (technically).

Most often, it's enough to implement OnFailedToConnectToPhoton() and OnDisconnectedFromPhoton().

OnJoinedLobby() or OnConnectedToMaster() are called when PUN is ready.

When this is called, the low level connection is established and PUN will send your AppId, the user, etc in the background.

This is not called for transitions from the masterserver to game servers.

Example: void OnConnectedToPhoton() { ... }

Called when the local userclient left a room.

When leaving a room, PUN brings you back to the Master Server.

Before you can use lobbies and join or create rooms, OnJoinedLobby() or OnConnectedToMaster() will get called again.

Example: void OnLeftRoom() { ... }

Called after switching to a new MasterClient when the current one leaves. The former already got removed from the player list.

This is not called when this client enters a room.

Example: void OnMasterClientSwitched(PhotonPlayer newMasterClient) { ... }

Called when a CreateRoom() call failed. Optional parameters provide ErrorCode and message.

Most likely because the room name is already in use (some other client was faster than you).

PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.

Example: void OnPhotonCreateRoomFailed() { ... }

Example: void OnPhotonCreateRoomFailed(object[] codeAndMsg) { codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }

Called when a JoinRoom() call failed. Optional parameters provide ErrorCode and message.

Most likely error is that the room does not exist or the room is full (some other client was faster than you).

PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.

Example: void OnPhotonJoinRoomFailed() { ... }

Example: void OnPhotonJoinRoomFailed(object[] codeAndMsg) { codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }

Called when this client created a room and entered it. OnJoinedRoom() will be called as well.

This callback is only called on the client which created a room (see PhotonNetwork.CreateRoom).

As any client might close (or drop connection) anytime, there is a chance that the

creator of a room does not execute OnCreatedRoom.

If you need specific room properties or a "start signal", it is safer to implement

OnMasterClientSwitched() and to make the new MasterClient check the room's state.

Example: void OnCreatedRoom() { ... }

Called on entering a lobby on the Master Server. The actual room-list updates will call OnReceivedRoomListUpdate().

Note: When PhotonNetwork.autoJoinLobby is false, OnConnectedToMaster() will be called and the room list won't become available.

While in the lobby, the roomlist is automatically updated in fixed intervals (which you can't modify).

Example: void OnJoinedLobby() { ... }

Called after leaving a lobby.

When you leave a lobby, [CreateRoom](@ref PhotonNetwork.CreateRoom) and [JoinRandomRoom](@ref PhotonNetwork.JoinRandomRoom)

automatically refer to the default lobby.

Example: void OnLeftLobby() { ... }

Called after disconnecting from the Photon server.

In some cases, other callbacks are called before OnDisconnectedFromPhoton is called.

Examples: OnConnectionFail() and OnFailedToConnectToPhoton().

Example: void OnDisconnectedFromPhoton() { ... }

Called when something causes the connection to fail (after it was established), followed by a call to OnDisconnectedFromPhoton().

If the server could not be reached in the first place, OnFailedToConnectToPhoton is called instead.

The reason for the error is provided as StatusCode.

Example: void OnConnectionFail(DisconnectCause cause) { ... }

Called if a connect call to the Photon server failed before the connection was established, followed by a call to OnDisconnectedFromPhoton().

OnConnectionFail only gets called when a connection to a Photon server was established in the first place.

Example: void OnFailedToConnectToPhoton(DisconnectCause cause) { ... }

Called for any update of the room listing (no matter if "new" list or "update for known" list). Only called in the Lobby state (on master server).

Not all types of lobbies provive a listing of rooms to the client. Some are silent and specialized for server-side matchmaking.

PUN provides the list of rooms by PhotonNetwork.GetRoomList().

Each item is a RoomInfo which might include custom properties

(provided you defined those as lobby-listed when creating a room).

Example: void OnReceivedRoomListUpdate() { ... }

Called when entering a room (by creating or joining it). Called on all clients (including the Master Client).

This method is commonly used to instantiate player characters.

If a match has to be started "actively", you can instead call an [RPC](@ref PhotonView.RPC) triggered by a user's button-press or a timer.

When this is called, you can usually already access the existing players in the room via PhotonNetwork.playerList.

Also, all custom properties should be already available as Room.customProperties. Check Room.playerCount to find out if

enough players are in the room to start playing.

Example: void OnJoinedRoom() { ... }

Called when a remote player entered the room. This PhotonPlayer is already added to the playerlist at this time.

If your game starts with a certain number of players, this callback can be useful to check the

Room.playerCount and find out if you can start.

Example: void OnPhotonPlayerConnected(PhotonPlayer newPlayer) { ... }

Called when a remote player left the room. This PhotonPlayer is already removed from the playerlist at this time.

When your client calls PhotonNetwork.leaveRoom, PUN will call this method on the remaining clients.

When a remote client drops connection or gets closed, this callback gets executed. after a timeout

of several seconds.

Example: void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { ... }

Called after a JoinRandom() call failed. Optional parameters provide ErrorCode and message.

Most likely all rooms are full or no rooms are available.

When using multiple lobbies (via JoinLobby or TypedLobby), another lobby might have morefitting rooms.

PUN logs some info if the PhotonNetwork.logLevel is >= PhotonLogLevel.Informational.

Example: void OnPhotonRandomJoinFailed() { ... }

Example: void OnPhotonRandomJoinFailed(object[] codeAndMsg) { codeAndMsg[0] is int ErrorCode. codeAndMsg[1] is string debug msg. }

Called after the connection to the master is established and authenticated but only when PhotonNetwork.autoJoinLobby is false.

If you set PhotonNetwork.autoJoinLobby to true, OnJoinedLobby() will be called instead of this.

You can join rooms and create them even without being in a lobby. The default lobby is used in that case.

The list of available rooms won't become available unless you join a lobby via PhotonNetwork.joinLobby.

Example: void OnConnectedToMaster() { ... }

Implement to customize the data a PhotonView regularly synchronizes. Called every 'network-update' when observed by PhotonView.

This method will be called in scripts that are assigned as Observed component of a PhotonView.

PhotonNetwork.sendRateOnSerialize affects how often this method is called.

PhotonNetwork.sendRate affects how often packages are sent by this client.

Implementing this method, you can customize which data a PhotonView regularly synchronizes.

Your code defines what is being sent (content) and how your data is used by receiving clients.

Unlike other callbacks, OnPhotonSerializeView only gets called when it is assigned

to a PhotonView as PhotonView.observed script.

To make use of this method, the PhotonStream is essential. It will be in "writing" mode" on the

client that controls a PhotonView (PhotonStream.isWriting == true) and in "reading mode" on the

remote clients that just receive that the controlling client sends.

If you skip writing any value into the stream, PUN will skip the update. Used carefully, this can

conserve bandwidth and messages (which have a limit per roomsecond).

Note that OnPhotonSerializeView is not called on remote clients when the sender does not send

any update. This can't be used as "x-times per second Update()".

Example: void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { ... }

Called on all scripts on a GameObject (and children) that have been Instantiated using PhotonNetwork.Instantiate.

PhotonMessageInfo parameter provides info about who created the object and when (based off PhotonNetworking.time).

Example: void OnPhotonInstantiate(PhotonMessageInfo info) { ... }

Because the concurrent user limit was (temporarily) reached, this client is rejected by the server and disconnecting.

When this happens, the user might try again later. You can't create or join rooms in OnPhotonMaxCcuReached(), cause the client will be disconnecting.

You can raise the CCU limits with a new license (when you host yourself) or extended subscription (when using the Photon Cloud).

The Photon Cloud will mail you when the CCU limit was reached. This is also visible in the Dashboard (webpage).

Example: void OnPhotonMaxCccuReached() { ... }

Called when a room's custom properties changed. The propertiesThatChanged contains all that was set via Room.SetCustomProperties.

Since v1.25 this method has one parameter: Hashtable propertiesThatChanged.

Changing properties must be done by Room.SetCustomProperties, which causes this callback locally, too.

Example: void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) { ... }

Called when custom player-properties are changed. Player and the changed properties are passed as object[].

Since v1.25 this method has one parameter: object[] playerAndUpdatedProps, which contains two entries.

[0] is the affected PhotonPlayer.

[1] is the Hashtable of properties that changed.

We are using a object[] due to limitations of Unity's GameObject.SendMessage (which has only one optional parameter).

Changing properties must be done by PhotonPlayer.SetCustomProperties, which causes this callback locally, too.

Example:

void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) {

PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;

Hashtable props = playerAndUpdatedProps[1] as Hashtable;

...

}

Called when the server sent the response to a FindFriends request and updated PhotonNetwork.Friends.

The friends list is available as PhotonNetwork.Friends, listing name, online state and

the room a user is in (if any).

Example: void OnUpdatedFriendList() { ... }

Called when the custom authentication failed. Followed by disconnect!

Custom Authentication can fail due to user-input, bad tokenssecrets.

If authentication is successful, this method is not called. Implement OnJoinedLobby() or OnConnectedToMaster() (as usual).

During development of a game, it might also fail due to wrong configuration on the server side.

In those cases, logging the debugMessage is very important.

Unless you setup a custom authentication service for your app (in the [Dashboard](https:cloud.exitgames.comdashboard)),

this won't be called!

Example: void OnCustomAuthenticationFailed(string debugMessage) { ... }

Called by PUN when the response to a WebRPC is available. See PhotonNetwork.WebRPC.

Important: The response.ReturnCode is 0 if Photon was able to reach your web-service.

The content of the response is what your web-service sent. You can create a WebResponse instance from it.

Example: WebRpcResponse webResponse = new WebRpcResponse(operationResponse);

Please note: Class OperationResponse is in a namespace which needs to be "used":

using ExitGames.Client.Photon; includes OperationResponse (and other classes)

The OperationResponse.ReturnCode by Photon is:

0 for "OK"

-3 for "Web-Service not configured" (see Dashboard WebHooks)

-5 for "Web-Service does now have RPC pathname" (at least for Azure)

Example: void OnWebRpcResponse(OperationResponse response) { ... }

Called when another player requests ownership of a PhotonView from you (the current owner).

The parameter viewAndPlayer contains:

PhotonView view = viewAndPlayer[0] as PhotonView;

PhotonPlayer requestingPlayer = viewAndPlayer[1] as PhotonPlayer;

void OnOwnershipRequest(object[] viewAndPlayer) {}

Used to define the level of logging output created by the PUN classes. Either log errors, info (some more) or full.

\ingroup publicApi

Show only errors. Minimal output. Note: Some might be "runtime errors" which you have to expect.

Logs some of the workflow, calls and results.

Every available log call gets into the consolelog. Only use for debugging.

Enum of "target" options for RPCs. These define which remote clients get your RPC call.

\ingroup publicApi

Sends the RPC to everyone else and executes it immediately on this client. Player who join later will not execute this RPC.

Sends the RPC to everyone else. This client does not execute the RPC. Player who join later will not execute this RPC.

Sends the RPC to MasterClient only. Careful: The MasterClient might disconnect before it executes the RPC and that might cause dropped RPCs.

Sends the RPC to everyone else and executes it immediately on this client. New players get the RPC when they join as it's buffered (until this client leaves).

Sends the RPC to everyone. This client does not execute the RPC. New players get the RPC when they join as it's buffered (until this client leaves).

Sends the RPC to everyone (including this client) through the server.

This client executes the RPC like any other when it received it from the server.

Benefit: The server's order of sending the RPCs is the same on all clients.

Sends the RPC to everyone (including this client) through the server and buffers it for players joining later.

This client executes the RPC like any other when it received it from the server.

Benefit: The server's order of sending the RPCs is the same on all clients.

Options of lobby types available. Lobby types might be implemented in certain Photon versions and won't be available on older servers.

This lobby is used unless another is defined by game or JoinRandom. Room-lists will be sent and JoinRandomRoom can filter by matching properties.

This lobby type lists rooms like Default but JoinRandom has a parameter for SQL-like "where" clauses for filtering. This allows bigger, less, or and and combinations.

Currently available cloud regions as enum.

Must match order in CloudServerRegionNames and CloudServerRegionPrefixes.

To keep things compatible with older ServerSettings, "none" is the final value, not the first.

Available server (types) for internally used field: server.

High level connection state of the client. Better use the more detailed .

Detailed connection networking peer state.

PUN implements a loadbalancing and authentication workflow "behind the scenes", so

some states will automatically advance to some follow up state. Those states are

commented with "(will-change)".

\ingroup publicApi

Not running. Only set before initialization and first use.

Created and available to connect.

Not used at the moment.

The application is authenticated. PUN usually joins the lobby now.

(will-change) Unless AutoJoinLobby is false.

Client is in the lobby of the Master Server and gets room listings.

Use Join, Create or JoinRandom to get into a room to play.

Disconnecting.

(will-change)

Connecting to game server (to joincreate a room and play).

(will-change)

Similar to Connected state but on game server. Still in process to joincreate room.

(will-change)

In process to joincreate room (on game server).

(will-change)

Final state of a room joincreate sequence. This client can now exchange events call RPCs with other clients.

Leaving a room.

(will-change)

Workflow is leaving the game server and will re-connect to the master server.

(will-change)

Workflow is connected to master server and will establish encryption and authenticate your app.

(will-change)

Same Queued but coming from game server.

(will-change)

PUN is disconnecting. This leads to Disconnected.

(will-change)

No connection is setup, ready to connect. Similar to PeerCreated.

Final state for connecting to master without joining the lobby (AutoJoinLobby is false).

Client connects to the NameServer. This process includes low level connecting and setting up encryption. When done, state becomes ConnectedToNameServer.

Client is connected to the NameServer and established enctryption already. You should call OpGetRegions or ConnectToRegionMaster.

When disconnecting from a Photon NameServer.

(will-change)

When connecting to a Photon Server, this state is intermediate before you can call any operations.

(will-change)

Photon properties, internally set by PhotonNetwork (PhotonNetwork builtin properties)

Summarizes the cause for a disconnect. Used in: OnConnectionFail and OnFailedToConnectToPhoton.

Extracted from the status codes from ExitGames.Client.Photon.StatusCode.

\ingroup publicApi

Connection could not be established.

Possible cause: Local server not running.

The security settings for client or server don't allow a connection (see remarks).

A common cause for this is that browser clients read a "crossdomain" file from the server.

If that file is unavailable or not configured to let the client connect, this exception is thrown.

Photon usually provides this crossdomain file for Unity.

If it fails, read:

http:doc.exitgames.comphoton-serverPolicyApp

Connection timed out.

Possible cause: Remote server not running or required ports blocked (due to router or firewall).

Timeout disconnect by client (which decided an ACK was missing for too long).

Exception in the receive-loop.

Possible cause: Socket failure.

Server actively disconnected this client.

Timeout disconnect by server (which decided an ACK was missing for too long).

Server actively disconnected this client.

Possible cause: Server's send buffer full (too much data for client).

Server actively disconnected this client.

Possible cause: The server's user limit was hit and client was forced to disconnect (on connect).

Some exception caused the connection to close.

(32756) Authorization on the Photon Cloud failed because the app's subscription does not allow to use a particular region's server.

(32757) Authorization on the Photon Cloud failed because the concurrent users (CCU) limit of the app's subscription is reached.

(32767) The Photon Cloud rejected the sent AppId. Check your Dashboard and make sure the AppId you use is complete and correct.

(32753) The Authentication ticket expired. Handle this by connecting again (which includes an authenticate to get a fresh ticket).

Internal state how this peer gets into a particular room (joining it or creating it).




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.566 lượt xem

Gõ tìm kiếm nhanh...